package com.hugy.test.controller;

import com.hugy.test.service.GridFsService;
import com.mongodb.client.gridfs.model.GridFSFile;
import lombok.SneakyThrows;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/gridFs")
public class GridFsController {

    @Resource
    private GridFsService gridFsService;

    @PostMapping("/add")
    public String add(){
        return gridFsService.add();
    }

    @PostMapping("/addTest")
    @SneakyThrows
    public String addTest(){
        return gridFsService.addTest();
    }

    @GetMapping("/select")
    @ResponseBody
    public String select(){
        String fileName = "d936.png";
        GridFSFile file = gridFsService.select(fileName);
        return file.getFilename();
    }

    @PostMapping("/delete")
    public String delete(){
        String fileName = "d936.png";
        gridFsService.delete(fileName);
        return "ok";
    }
}
